package com.etoak.config;

import com.etoak.common.core.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Service
//网关处理静态资源访问
public class WebFluxConfig implements WebFluxConfigurer {
    @Autowired
    ImageProperties imageProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //mapping: /pics/**
        String mapping = imageProperties.getMapping().endsWith("/")?
                imageProperties.getMapping()+"**" :
                imageProperties.getMapping()+"/**";
        //location:  d:/upload/et2504/
        String location = imageProperties.getUploadDir().endsWith("/")?
                imageProperties.getUploadDir() :
                imageProperties.getUploadDir()+"/";
        registry.addResourceHandler(mapping).addResourceLocations("file:"+location);
    }
}
